home *** CD-ROM | disk | FTP | other *** search
- /*
- * Program to test speed of file access by gaining contents of
- * specified files and dumping them to stdout
- *
- * (c) Martin Houston.
- */
-
- #include <stdio.h>
- #include <fcntl.h>
- #include <errno.h>
- #include <sys/types.h>
- #include <sys/stat.h>
- #include <sys/ndir.h>
- #include <sys/timeb.h>
-
- extern int errno;
- extern char *sys_errlist[];
-
- DIR *opendir();
- struct direct *readdir();
-
- long time();
-
- long nfiles = 0L; /* number of files accessed */
- long bytecount = 0L; /* total data xfered */
-
- main(argc, argv)
- int argc;
- char **argv;
- {
- int file;
- long starttime, endtime;
- float mbm;
- struct timeb tb;
-
-
- ftime(&tb);
- starttime = (tb.time * 1000) + tb.millitm;
-
- for(file = 1; file < argc; doname(argv[file++]))
- ;
-
- ftime(&tb);
- endtime = (tb.time * 1000) + tb.millitm;
- endtime -= starttime;
-
- fprintf(stdout,"ft transfers %ld bytes from %ld files in %ld milli-secs\n",
- bytecount, nfiles, endtime);
-
- /*
- * We have bytes transferred and milli seconds.
- * We want a figure in MB/Min.
- */
- mbm = (float)((float)bytecount / (float)1024 / (float)1024)
- / (float)((float)endtime / (float)1000 / (float)60);
- fprintf(stdout,"transfer rate = %f MB/MIN\n",mbm);
- exit(0);
- }
-
- doname(name)
- char *name;
- {
- static struct stat sbuf;
-
- if(stat(name, &sbuf) < 0)
- {
- dobad(name); /* Can't get status */
- }
- else
- if((sbuf.st_mode & S_IFMT) == S_IFDIR)
- {
- dodir(name); /* is a directory */
- }
- else
- if((sbuf.st_mode & S_IFMT) == S_IFREG)
- {
- dofile(name, sbuf.st_size); /* is a file */
- }
- }
-
- dobad(name)
- char *name;
- {
- fprintf(stdout,"Error \"%s\" from %s\n", sys_errlist[errno], name);
- }
-
- dodir(name)
- char *name;
- {
-
- DIR *dirp;
- struct direct *dp;
-
- if(chdir(name) < 0)
- {
- dobad("Directory Push Operation");
- }
- else
- if((dirp = opendir(".")) != NULL)
- {
- for(dp = readdir(dirp); dp != NULL; dp = readdir(dirp))
- {
- #ifdef DEBUG
- fprintf(stdout, "Scanning directory entry %s\n", dp->d_name);
- #endif
- if((dp->d_namlen > 2) ||
- (strcmp(dp->d_name, ".") && strcmp(dp->d_name,"..")))
- {
- /* Not . or .. */
- doname(dp->d_name);
- }
- }
- closedir(dirp);
- }
- if(chdir("..") < 0)
- {
- dobad("Directory Pop Operation");
- }
- }
-
- dofile(name, bytes)
- char *name;
- long bytes;
- {
- static char buf[30000];
- int fd, xfer;
-
- /* take stats */
- nfiles++;
- bytecount += bytes;
-
- #ifdef DEBUG
- fprintf(stdout, "Xfer of %ld bytes from %s\n", bytes, name);
- #endif
-
- if((fd = open(name, O_RDONLY)) < 0)
- {
- dobad(name);
- }
- else
- {
- while(bytes > 0L)
- {
- /* read the file into the buffer */
- xfer = (bytes > (long)sizeof(buf) ? sizeof(buf) : (int)bytes);
- xfer = read(fd, buf, xfer);
- bytes -= xfer;
- }
- close(fd);
- }
- }
-
-